11 November 2020

About this document

This is an R Markdown presentation and it is created using Rstudio.

RStudio is an integrated development environment (IDE) for R. RStudio is available in open source and commercial editions and runs on the desktop (Windows, Mac, and Linux).

R is a language and environment for statistical computing and graphics. R provides a wide variety of statistical (linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, clustering, …) and graphical techniques, and is highly extensible. R is available as Free Software.

Steps

  • Determinate the Libraries to use
  • Read the file and transformation the data
  • Selection of the more appropiated kind of chart to represent the information
  • Creation of dynamic timeline chart

Libraries used

R packages are a collection of R functions, complied code and sample data. They are stored under a directory called “library” in the R environment. By default, R installs a set of packages during installation. More packages are added later, when they are needed for some specific purpose.

library(readxl) #Reading the data from excel sheet
library(DT) #Show the dynamic table
library(highcharter) #Representing the data in timelines chart

Load of the table and any other changes in the data

#Load the table, stablishing the sheet, range and column types of the data

Turtle <- read_excel("E:/Trabajos Fran/Ostional/Nesting_and_Harvesting_DATA_Students.xlsx", 
                     sheet = "Chart", range = cell_cols("A1:C43"), 
                     col_types = c("numeric", "numeric", "date")) 

#Change of column names

names(Turtle)[1] <- "egglaying"
names(Turtle)[2] <- "nharv"

#Convert of Date column to Timestamp column

turtle.date <- ts(data=Turtle, 
                  start = c(2006,06), 
                  end = c(2010,12), 
                  frequency = 12)

Creating a table

table <- datatable(turtle.date, extensions = c('Buttons','FixedColumns', 'RowReorder'),
  filter = list(position = 'top', clear = FALSE),
  options = list(dom = 'Bfrtip',
    buttons = c('copy', 'csv', 'excel', 'pdf', 'print'), dom = 't',
    scrollX = TRUE,
    fixedColumns = TRUE,
    rowReorder = TRUE, order = list(c(0 , 'asc'))))

Consulting the table

Creating the Timelines Dynamic Chart

#Creating the Timelines chart

Chart <- highchart(type = "stock") %>% 
  hc_title(text = "Total Eggs Laying Female and Percent of nests harvested") %>% 
  hc_subtitle(text = "Ostional - Costa Rica, Period 2006-2010") %>%
  hc_yAxis_multiples(list(title = list(text = "Eggs laying"), opposite = FALSE),
                    list(showLastLabel = FALSE, opposite = TRUE, 
                            title = list(text = "Nests harvested"))) %>% 
  hc_add_series(turtle.date[,1],  yAxis = 0, type = "line", 
                pointInterval= 30*24*3600*1000, 
                name="Total Eggs Laying Female", color = "#ffa500")%>%
  hc_add_series(turtle.date[,2],  yAxis = 1, type = "line", 
                pointInterval= 30*24*3600*1000, 
                name="Percent of nests harvested", color = "#13ED3F")%>%
  hc_xAxis(title= list(text='Date'), type='datetime')

Timelines Dynamic Chart